package com.kexilo.core.shared.dto;

import java.util.List;
import java.util.ArrayList;

/**
 * 通用树形节点DTO
 * 
 * 用于在common模块中表示任何树形数据结构，避免直接依赖具体的业务实体
 * 支持菜单树、部门树、区域树等各种树形数据
 * 
 * @author Kexilo
 */
public class TreeNodeDTO {
    
    /** 节点ID */
    private Long id;
    
    /** 节点标签 */
    private String label;
    
    /** 父节点ID */
    private Long parentId;
    
    /** 子节点列表 */
    private List<TreeNodeDTO> children;
    
    /** 扩展属性 - 可用于存储额外信息 */
    private Object data;
    
    public TreeNodeDTO() {
        this.children = new ArrayList<>();
    }
    
    public TreeNodeDTO(Long id, String label) {
        this();
        this.id = id;
        this.label = label;
    }
    
    public TreeNodeDTO(Long id, String label, Long parentId) {
        this(id, label);
        this.parentId = parentId;
    }
    
    /**
     * 添加子节点
     */
    public void addChild(TreeNodeDTO child) {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        this.children.add(child);
    }
    
    /**
     * 判断是否有子节点
     */
    public boolean hasChildren() {
        return children != null && !children.isEmpty();
    }
    
    // Getter and Setter methods
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getLabel() {
        return label;
    }
    
    public void setLabel(String label) {
        this.label = label;
    }
    
    public Long getParentId() {
        return parentId;
    }
    
    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }
    
    public List<TreeNodeDTO> getChildren() {
        return children;
    }
    
    public void setChildren(List<TreeNodeDTO> children) {
        this.children = children;
    }
    
    public Object getData() {
        return data;
    }
    
    public void setData(Object data) {
        this.data = data;
    }
}
